import {readFile, writeFile} from "fs";

readFile("dist/index.html", "utf8", (err, htmlString) => {
    if (err) {
        throw err;
    }
    // 正则匹配 href 双引号中的内容
    const herfRegex = /href="(.*)"/g;  const srcRegex = /src="(.*)"/g;
    const replacedHtml = htmlString.replace(herfRegex, "href=\"{% static '$1' %}\"").replace(srcRegex, "src=\"{% static '$1' %}\"");
    writeFile("dist/index.html", "{% load static %}\n" + replacedHtml, "utf8", (err) => {
        if (err) {
            throw err;
        }
        console.log("文件替换完成");
    });
});